import {Component, OnInit} from '@angular/core';
import {FormControl, FormGroup} from "@angular/forms";
import {BarnProject} from "../entity/barn-project";
import {ProjectService} from "../service/project.service";

@Component({
  selector: 'app-project-mine',
  templateUrl: './project-mine.component.html',
  styleUrls: ['./project-mine.component.less']
})
export class ProjectMineComponent implements OnInit {

  validateForm = new FormGroup({
    projectName: new FormControl(),
    enable: new FormControl('')
  })
  projects: BarnProject[] = []
  loading = false


  constructor(private projectService: ProjectService) {
  }

  ngOnInit(): void {
    this.search();
  }

  search() {
    this.loading = true
    const param = this.validateForm.getRawValue();
    this.projectService.mine(param)
      .subscribe(value => {
        this.projects = value
        this.loading = false
      }, () => this.loading = false)

  }

  resetForm() {
    this.validateForm.reset({enable: '',})
  }
}
